package com.xxtx.trade.wx.service.impl;

import com.xxtx.trade.wx.bean.TradeWxUser;
import com.xxtx.trade.wx.mapper.WxUserMapper;
import com.xxtx.trade.wx.service.IWxUserService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 功能描述:
 *
 * @Params:
 * @Author: xuliang
 * @email: northly@live.com
 * @Date: 2020/1/12 13:52
 */
@Service
public class WxUserService implements IWxUserService {

    @Autowired
    private WxUserMapper wxUserMapper;

    @Override
    public TradeWxUser queryByPrimaryKey(String key) {
        return wxUserMapper.queryByPrimaryKey(key);
    }

    @Transactional
    @Override
    public boolean saveOrUpdate(TradeWxUser tradeWxUser) {
        TradeWxUser record = queryByPrimaryKey(tradeWxUser.getIccid());
        if(record == null){
            return wxUserMapper.insert(tradeWxUser) > 0;
        }
        return wxUserMapper.update(tradeWxUser) > 0;
    }
}
